<?php
//include all support file
include_once ("../modconfig.php");
include_once ("$ROOT_CLASS_DIR/class_database.php");
include_once ("$ROOT_CLASS_DIR/class_common.php");
include_once ("$ROOT_CLASS_DIR/class_login.php");

require_once('OLEwriter.php');
require_once('BIFFwriter.php');
require_once('Worksheet.php');
require_once('Workbook.php');

global $DBCoins,$DBGeneral,$DBConnection, $RS,$Index, $a, $b;


function HeaderingExcel($filename){
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:attachment;filename=$filename");
    header("Expires:0");
    header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
    header("Pragma: public");
}

list($day,$month,$year)=explode("/", GetParam("fromDate",""));
$date1 = "$year-$month-$day";
list($day,$month,$year)=explode("/", GetParam("toDate",""));
$date2 = "$year-$month-$day";

$office = GetParam("office","");
$coa = GetParam("fromCOA","");

$namafile = 'Account Acc'.$date1.'-to-'.$date2.'-'.GetParam("fromCOA","");

//http headers
HeaderingExcel($namafile);

//make a workbook
$workbook=new Workbook("-");

//make first worksheet
$fJudul=& $workbook->add_format();
$fJudul->set_bold();
$fJudul->set_size(14);

$fFooter=& $workbook->add_format();
$fFooter->set_bold();
$fFooter->set_size(11);


$fJudulKolom=& $workbook->add_format();
$fJudulKolom->set_bold();
$fJudulKolom->set_size(8);
$fJudulKolom->set_align('centre');
$fJudulKolom->set_border(1);

$fBesar=& $workbook->add_format();
$fBesar->set_size(20);

$fKutipan=& $workbook->add_format();
$fKutipan->set_align('right');
$fKutipan->set_italic();
$fKutipan->set_size(8);
$fKutipan->set_color('blue');

$fList=& $workbook->add_format();
$fList->set_size(8);

$fIsi=& $workbook->add_format();
$fIsi->set_border(1);

$fIsiTengah=& $workbook->add_format();
$fIsiTengah->set_border(1);
$fIsiTengah->set_align('centre');

$worksheet1= & $workbook->add_worksheet("Sheet 1");
//seting zoom size
//75 is 75% zoom size
$worksheet1->set_zoom(75);

//set portrait page
$worksheet1->set_portrait(75);

//set a4 paper size
$worksheet1->set_paper(9);

//set hide gridlines
$worksheet1->hide_gridlines();

//set print area
$worksheet1->print_area(0,0,15,5);

//set page header
$worksheet1->set_header("header",$margin=2);


//set column
$worksheet1->set_column(1,1,5);
$worksheet1->set_column(2,2,17);
$worksheet1->set_column(3,3,22);
$worksheet1->set_column(4,4,12);
$worksheet1->set_column(5,5,40);
$worksheet1->set_column(6,6,14);
$worksheet1->set_column(7,7,35);
$worksheet1->set_column(8,8,17);
$worksheet1->set_column(9,9,17);


// buat koneksi database dan cari data
$DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);


	
//con.MTCODE  
$SQL  = "
	 			SELECT nobkt,vat,debnam,tglbkt,skada,uraian,dk,rupiah
	 			FROM ais_memorial WHERE ktrasl = '".$office."' AND skada = '".$coa."' AND tglbkt >= '".$date1."' AND tglbkt <='".$date2."' 
				ORDER BY nobkt ASC";

$Result = $DBConnection->dbc->get_results($SQL, ARRAY_A);

$title1 = "ACCOUNT ACTIVITY";
$title2 = "PT. Masaji Tatanan Container";

//Judul
$worksheet1->write_string(1,1,$title1,$fJudul);
$worksheet1->write_string(3,1,$title2,$fJudul);
//$worksheet1->write_string(4,1,"Office : ".$office,$fJudul);
$worksheet1->write_string(5,1,"Coa : ".$coa,$fJudul);


//column header 
$worksheet1->write_string(7,1,"No",$fJudulKolom);
$worksheet1->write_string(7,2,"Trans No",$fJudulKolom);
$worksheet1->write_string(7,3,"Vat Number",$fJudulKolom);
$worksheet1->write_string(7,4,"Date",$fJudulKolom);
$worksheet1->write_string(7,5,"Debitur Name",$fJudulKolom);
$worksheet1->write_string(7,6,"Skada",$fJudulKolom);
$worksheet1->write_string(7,7,"Description",$fJudulKolom);
$worksheet1->write_string(7,8,"Debet",$fJudulKolom);
$worksheet1->write_string(7,9,"Kredit",$fJudulKolom);
//$a = 7;
if ($Result) {
foreach ($Result as $row) {
    
	$a++;
    $worksheet1->write_number($a,1,$a,$fIsi);
    $worksheet1->write_string($a,2,$row["nobkt"],$fIsi);
    $worksheet1->write_string($a,3,$row["vat"],$fIsi);
    $worksheet1->write_string($a,4,$row["tglbkt"],$fIsiTengah);
    $worksheet1->write_string($a,5,$row["debnam"],$fIsi);
    $worksheet1->write_string($a,6,$row["skada"],$fIsiTengah);
    $worksheet1->write_string($a,7,$row["uraian"],$fIsi);
	
	if ($row["dk"]=='D') $row["rupiah1"] = $row["rupiah"];
	else $row["rupiah2"] = $row["rupiah"];
   $worksheet1->write_number($a,8,$row["rupiah1"],$fIsi);
	$worksheet1->write_number($a,9,$row["rupiah2"],$fIsi);
 }
 }
	
$workbook->close();
?>
